
import Image from "./image";

export default class Button extends Image {
    constructor(pathokey, name) {
        super(pathokey, name);
        this._effscale = 1.2;
    }
   
    setTap(func) {
         /* 点击事件 */
        if (typeof (func) != "function") {
            console.error("setTap param typeof 'function'"); 
            return;
        }
        this._begainfunc = func;
        return this;
    }

    _touchstart(evt) {
        this._bscalex = this.scale.x, this._bscaley = this.scale.y;
        this.scale.set(this.scale.x * this._effscale, this.scale.y * this._effscale, 1);
    }

    _touchend(evt) {
        if (typeof (this._begainfunc) == "function") {
            this._begainfunc();
        }
        this.scale.set(this._bscalex, this._bscaley, 1);    
    }

    _touchcancel() {
        this.scale.set(this._bscalex, this._bscaley, 1);
    }
}